//
//  NetworkingHandle.h
//  IYoker_Organization
//
//  Created by chunjian Dai on 15/12/19.
//  Copyright © 2015年 wangguimin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"

/**
 *  网络请求的分类：相同页面区分不同的网络请求
 */
typedef NS_ENUM(NSUInteger, NetWorkingType) {
 
    NetWorkingType0,
 
    NetWorkingType1,
 
    NetWorkingType2,
   
    NetWorkingType3,
    
    NetWorkingType4,
    
    
};

typedef NS_ENUM(NSUInteger, RequestType) {
    
    RequestTypeGet,
    RequestTypePost,
    
};


@class NetworkingHandle;
@protocol NetworkingHandleDelegate <NSObject> //    网络请求结果的代理方法
@optional
- (void)networkingHandleSuccess:(NetworkingHandle *)handle
                     parameters:(NSDictionary *)parameters
                 responseObject:(id)responseObject
                           type:(NetWorkingType)type;

- (void)networkingHandleWarning:(NetworkingHandle *)handle
                 responseObject:(id)responseObject
                           type:(NetWorkingType)type;

- (void)networkingHandlefail:(NetworkingHandle *)handle
                        type:(NetWorkingType)type;
//  下载进度
- (void)networkingHandle:(NetworkingHandle *)handle
        downloadProgress:(NSProgress *)progress
                    type:(NetWorkingType)type;
//  上传进度
- (void)networkingHandle:(NetworkingHandle *)handle
          uploadProgress:(NSProgress *)progress
                    type:(NetWorkingType)type;

@end


@interface NetworkingHandle : NSObject

@property (nonatomic,strong) AFHTTPSessionManager *manager;

@property (nonatomic,assign) RequestType requestType;// 网络请求类型

@property (nonatomic,strong) NSMutableArray *taskArray;

- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;

/**
 *  普通网络请求
 *
 *  @param URL        网址
 *  @param parameters 参数字典
 *  @param delegate   代理对象
 *  @param type       区分同一界面的不同网络请求
 *  @param requestType 网络请求类别:get和post
 *
 *  @return 网络请求结果
 */
+ (id)handleWithURL:(NSString *)URL
         parameters:(NSDictionary *)parameters
           delegate:(id<NetworkingHandleDelegate>)delegate
               type:(NetWorkingType)type
        requestType:(RequestType)requestType;

- (id)initWithURL:(NSString *)URL
       parameters:(NSDictionary *)parameters
         delegate:(id<NetworkingHandleDelegate>)delegate
             type:(NetWorkingType)type
      requestType:(RequestType)requestType;

//- (void)getNetworkingWithURL:(NSString *)URL
//                  parameters:(NSDictionary *)parameter
//                        type:(NetWorkingType)type
//                    delegate:(id<NetworkingHandleDelegate>)delegate;

- (void)postNetworkingWithURL:(NSString *)URL
               parameters:(NSDictionary *)parameters
                         type:(NetWorkingType)type
                     delegate:(id<NetworkingHandleDelegate>)delegate;


//  下载
+ (id)handleDownWithURL:(NSString *)URL
                   path:(NSString *)path
               delegate:(id<NetworkingHandleDelegate>)delegate
                   type:(NetWorkingType)type;
- (id)initDownWithURL:(NSString *)URL
                 path:(NSString *)path
             delegate:(id<NetworkingHandleDelegate>)delegate
                 type:(NetWorkingType)type;
- (void)downLoadWithURL:(NSString *)URL
                   path:(NSString *)path
                   type:(NetWorkingType)type
               delegate:(id<NetworkingHandleDelegate>)delegate;



//  多张图片的上传
- (void)postNetworkingWithURL:(NSString *)URL
                 imagePicName:(NSString *)imagePicName
                   imageArray:(NSArray *)imageArray
                   parameters:(NSDictionary *)parameters
                         type:(NetWorkingType)type
                     delegate:(id<NetworkingHandleDelegate>)delegate;

//  单张图片的上传
- (void)postNetworkingWithURL:(NSString *)URL
                 imagePicName:(NSString *)imagePicName
                        image:(UIImage *)image
                   parameters:(NSDictionary *)parameters
                         type:(NetWorkingType)type
                     delegate:(id<NetworkingHandleDelegate>)delegate;
@end
